#include <stdio.h>
#include <unistd.h>

#define NUM 101
#define SYM '#'

// '\'为转义字符。
char s[5] = "|\\-/";

void process(double total,double current)
{
	int num = (int)current * 100 / total;
	char str[NUM] = "";
	for(int i = 0;i < num;++i)
	{
		str[i] = SYM;	
	}

	str[num] = '\0';

	printf("[%-100s] [%.2lf] [%c]\r",str,(double)current * 100 / total , s[num % 4]);
	fflush(stdout);
}

void download()
{
	double total = 1024.0;
	double rate = 1.0;
	double current = 0.0;

	while((double)current <= total)
	{
		sleep(1);
		process(total,current);
		current += rate;	
	}

	printf("\nDownload:%.2lf",current);
}

void running()
{
    int count = 0;
    char str[NUM] = "";
    while(count < NUM)
    {
	printf("[%-100s] [%c] [%d%%]\r",str,s[count % 4],count);
	str[count] = SYM;
	sleep(1);
	fflush(stdout);
	++count;
    }
    s[0] = '\0';
    printf("\nThe work is finishing");
}

int main()
{
	 // running();
	
	download();

	 return 0;
}
